package avriServer.json;

/**
 * Return the string which will be pushed to the waiters/workers on JSON format.
 */
public class JSONData extends JSONStringer {
	public JSONData (String _functionName, String... _attributes) {
		super();
	}
	/**
	 * @param _action
	 * @param _value
	 * @return String of a basic data JSON object {action: _action, attributes: _value}
	 */
	public String getAction (String _action, String _attributes) {
		try {
			this.object()
				.key("action")
				.value(_action)
				.key("attributes")
				.value(_attributes)
			.endObject();
		} catch (JSONException e) {
			return this.getInternalError();
		}
		return this.toString() ;
	}
	public String getAction (String _action, boolean _attributes) {
		try {
			this.object()
				.key("action")
				.value(_action)
				.key("value")
				.value(_attributes)
			.endObject();
		} catch (JSONException e) {
			return this.getInternalError();
		}
		return this.toString() ;
	}
	/**
	 * @param _error
	 * @return String of a basic data JSON error object {action: "error", attributes: _error}
	 */
	public String getError (String _error) {
		return this.getAction("error", _error);
	}
	/**
	 * @param _error
	 * @return String of a basic data JSON info object {action: "info", attributes: _info}
	 */
	public String getInfo (String _info) {
		return this.getAction("info", _info);
	}
	
	public String getInternalError () {
		return this.getError("Server internal Error");
	}
	public String getKeepAlive() {
		return this.getAction("keepAlive", Long.toString(System.currentTimeMillis()));
	}
}
